<template>
    <div class="shop">
        <van-nav-bar
                :title="name"
                left-arrow
                @click-left="onClickLeft"
        />
        <div style="display: flex;padding: 12px;
    background-color: #fff;">
            <div style="width:100px;">
                <p><img :src="img" alt="" style="width:100%;"></p>
            </div>
            <div style="margin-left: 7px!important;font-size: 14px;width:53%;">
                <p><span>{{name}}</span><span style="border-radius: 4px;
    color: #fff;
    font-size: 10px;
    width: 30px;
    text-align: center;
    padding: 2px 4px;background: linear-gradient(90deg,#fd5632 0,#ef0d25);margin-left: 5px!important;color: #fff;
    font-size: 10px;
    text-align: center;">自营</span></p>
                <p>{{gz}}人关注</p>
            </div>
            <div @click="collect">
                <div style="border: 1px solid #ccc;
    border-radius: 16px;
    font-size: 11px;
    padding: 5px 10px;margin-top: 5px;">
                    <van-icon name="like-o">收藏</van-icon>
                </div>
            </div>
        </div>
        <!--搜索模块-->
        <div v-if="Chi=='Allgoods'" style="background-color: #fff;
    padding: 10px;display: flex;color: #303133;
    font-size: 14px;justify-content: space-between">
            <router-link to="/homeSearch">
                <el-input
                        placeholder="搜索店内商品"
                        prefix-icon="el-icon-search"
                        v-model="input2">
                </el-input>
            </router-link>
            <span style="line-height: 21px;
    padding: 0 10px;
    border: 1px solid #ccc;
    border-radius: 16px;
    font-size: 11px;height:22px;margin-top: 10px" @click="Chi='Shopstype'">店铺分组</span>
        </div>
        <!--动态组件显示-->
        <transition :name="aName" mode="out-in">
            <component :is="Chi"></component>
        </transition>
        <!--组件切换-->
        <div style="display: flex;justify-content: space-between;position: fixed;bottom:0;width:100%;background-color:#ffffff;"
             class="tp">
            <div @click="Chi='Homepage'">
                <i class="iconfont" :class="{bg:Chi=='Homepage'}">&#xe605;</i>
                <p>店铺首页</p>
            </div>
            <div @click="Chi='Allgoods'">
                <i class="iconfont" :class="{bg:Chi=='Allgoods'}">&#xe86a;</i>
                <p>全部商品</p>
            </div>
            <div @click="Chi='Shopstype'">
                <i class="iconfont" :class="{bg:Chi=='Shopstype'}">&#xe604;</i>
                <p>店铺分组</p>
            </div>
            <div @click="Chi='service'">
                <i class="iconfont" :class="{bg:Chi=='service'}">&#xe61c;</i>
                <p>客服</p>
            </div>
        </div>
    </div>
</template>

<script>
    import jsp from '../../Api/Api'
    import Vue from 'vue'
    import {Dialog} from 'vant';
    import Allgoods from "./Allgoods/Allgoods";
    import Homepage from "./Homepage/Homepage";
    import Service from "./Service/service";
    import Shopstype from "./Shopstype/Shopstype";

    Vue.use(Dialog);

    export default {
        name: "Shops",
        components: {Shopstype, Service, Homepage, Allgoods},
        data() {
            return {
                Chi: 'Homepage',
                name: '',
                img: '',
                gz: 0,
                aName: 'slide-left',
                input2: ''
            }
        },
        watch: {
            '$route'(to, from) {
                const toDepth = to.path.split('/').length
                const fromDepth = from.path.split('/').length
                this.aName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
            }
        },
        created() {
            let a = this.$route.query.shop_id
            // console.log(a)
            jsp.shopMsg(a).then(data => {
                // console.log(data.data)
                this.name = data.data.shop_name
                this.img = data.data.shop_logo
                this.gz = data.data.shop_collect
            })
            let b = location.hash.split('/')
            if (b.length == 3) {
                this.Chi = 'Allgoods'
            }
        },
        methods: {
            onClickLeft() {
                this.$router.push('/home')
            },
            collect() {
                Dialog.confirm({
                    title: '提示',
                    message: '您还未登录，请先登录~',
                    cancelButtonText: '再逛逛',
                    confirmButtonText: '去登录',
                }).then(() => {
                    this.$router.push('/enter')
                }).catch(() => {

                });
            },
            go() {
                console.log(1111)
            }
        },
    }
</script>

<style scoped>
    >>> .van-nav-bar .van-icon {
        color: #000 !important;
    }

    >>> .van-hairline--bottom::after {
        border: none;
    }

    @font-face {
        font-family: 'iconfont';  /* Project id 2384427 */
        src: url('http://at.alicdn.com/t/font_2384427_ase9wsmajvm.woff2?t=1623812722967') format('woff2'),
        url('http://at.alicdn.com/t/font_2384427_ase9wsmajvm.woff?t=1623812722967') format('woff'),
        url('http://at.alicdn.com/t/font_2384427_ase9wsmajvm.ttf?t=1623812722967') format('truetype');
    }

    .iconfont {
        font-family: "iconfont" !important;
        font-size: 18px;
        font-style: normal;
        -webkit-font-smoothing: antialiased;
        -webkit-text-stroke-width: 0.2px;
        -moz-osx-font-smoothing: grayscale;
    }

    .tp div {
        width: 25%;
        padding: 6px 0;
        text-align: center;
        box-sizing: border-box;
    }

    .tp p {
        font-size: 13px;
    }

    .bg {
        color: #66b1ff;
    }

    .el-input {
        width: 275px !important;
    }

    >>> .el-input__inner {
        border-radius: 20px !important;
    }

    .slide-left-enter-to {
        opacity: 1;
        transform: translateX(0);
    }

    .slide-left-leave-to, .slide-left-enter, .slide-left-leave {
        opacity: 0;
    }

    .slide-right-enter-active, .slide-right-leave-active, .slide-left-enter-active, .slide-left-leave-active {
        transition: all .5s;
    }

    .slide-right-enter, .slide-right-leave-to {
        opacity: 0;
    }

    .slide-right-enter-to {
        opacity: 1;
    }

    .slide-right-leave {
        opacity: 0;
    }
</style>